/*
 *  Jajuk
 *  Copyright (C) 2003-2008 The Jajuk Team
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  as published by the Free Software Foundation; either version 2
 *  of the License, or any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *  $Revision: 3132 $
 */
package aspecto;

/**
 * 
 */
privileged public aspect TrackManagerAspect {

  pointcut changeMethods(org.jajuk.base.Track t):
    execution(* org.jajuk.base.TrackManager.change*(org.jajuk.base.Track,..))&&args(t,..) && within(org.jajuk.base.TrackManager) && (!withincode(* org.jajuk.base.TrackManager.changeTrackRate(..)) && !withincode(* org.jajuk.base.TrackManager.changeTrackOrder(..)));
  
  org.jajuk.base.Track around(org.jajuk.base.Track t): changeMethods(t){
    synchronized (org.jajuk.base.TrackManager.getInstance().getLock()) {
      org.jajuk.base.TrackManager.track = t;
      return proceed(t);
    }
  }
 
  pointcut commitTag(org.jajuk.services.tags.Tag t):
    call(* org.jajuk.services.tags.Tag.set*(String))&& target(t) && withincode(* org.jajuk.base.TrackManager.change*(..));
    
  after(org.jajuk.services.tags.Tag t) throws org.jajuk.util.error.JajukException: commitTag(t){
    t.commit();
  }
 
  pointcut changeTrackAlbumAspect():
    call(* org.jajuk.base.Album.equals(..)) && withincode(* org.jajuk.base.TrackManager.changeTrackAlbum(..));
 
  before(): changeTrackAlbumAspect(){
    org.jajuk.base.TrackManager.track.getAlbum().tracks.remove(org.jajuk.base.TrackManager.track);
  }
  
  pointcut changeTrackAuthorAspect():
    call(* org.jajuk.base.Author.equals(..)) && withincode(* org.jajuk.base.TrackManager.changeTrackAuthor(..));
 
  before(): changeTrackAuthorAspect(){
    org.jajuk.base.TrackManager.track.getAlbum().tracks.remove(org.jajuk.base.TrackManager.track);
  }
  
  pointcut changeTrackStyleAspect():
    call(* org.jajuk.base.StyleManager.registerStyle(String)) && withincode(* org.jajuk.base.TrackManager.changeTrackStyle(..));
 
  before(): changeTrackStyleAspect(){
    org.jajuk.base.TrackManager.track.getAlbum().tracks.remove(org.jajuk.base.TrackManager.track);
  }
  
  pointcut changeTrackYearAspect():
    call(* org.jajuk.base.YearManager.registerYear(String)) && withincode(* org.jajuk.base.TrackManager.changeTrackYear(..));
 
  before(): changeTrackYearAspect(){
    org.jajuk.base.TrackManager.track.getAlbum().tracks.remove(org.jajuk.base.TrackManager.track);
  }
  
  pointcut changeTrackCommentAspect():
    call(* org.jajuk.base.Track.setComment(String)) && withincode(* org.jajuk.base.TrackManager.changeTrackComment(..));
 
  before(): changeTrackCommentAspect(){
    org.jajuk.base.TrackManager.track.getAlbum().tracks.remove(org.jajuk.base.TrackManager.track);
  }
  
  pointcut changeTrackNameAspect():
    call(* org.jajuk.base.TrackManager.registerTrack(..)) && withincode(* org.jajuk.base.TrackManager.changeTrackName(..));
 
  before(): changeTrackNameAspect(){
    org.jajuk.base.TrackManager.track.getAlbum().tracks.remove(org.jajuk.base.TrackManager.track);
  }
}
